$(function () {
    /*动态计算搜索框input宽度*/
    // var oInput = $('#js-y-search .normal_input');
    // $.each(oInput, function (index, value) {
    //     var oP = $(value).parent();
    //     ow = oP.width() - oP.find('.name').width();
    //     $(value).width(160 + 'px');
    // });


    /*点击x关闭整个弹窗*/
    //缓存弹窗
    var w_frame = $('.modal_fixed');
    $(document).on('click','.modal_close',function () {
        $(this).closest('.modal_fixed').hide();
    });

    /*点击 费用结算 修改费用*/
    $('#y-js-table').on('click', '.y-change-money-btn', function () {
        var id = $(this).data('id');
        var otr = $(this).closest('tr');
        var befort = otr.data('befort');
        var sign = otr.data('sign');
        var receipt = otr.data('receipt');
        var cycle = otr.data('cycle');

        var before_pay_type = otr.data('before_pay_type');
        var sign_pay_type = otr.data('sign_pay_type');
        var receipt_pay_type = otr.data('receipt_pay_type');
        var cycle_pay_type = otr.data('cycle_pay_type');
        var total_fee = otr.data('total');
        var window_frame = $('#tms_sj_change_money');

        window_frame.find('.pay_node_before').val(befort);
        window_frame.find('.pay_node_sign').val(sign);
        window_frame.find('.pay_node_receipt').val(receipt);
        window_frame.find('.pay_node_cycle').val(cycle);


        console.log(before_pay_type, sign_pay_type, receipt_pay_type);
        window_frame.find('.before_pay_type').val(before_pay_type);
        window_frame.find('.sign_pay_type').val(sign_pay_type);
        window_frame.find('.receipt_pay_type').val(receipt_pay_type);
        window_frame.find('.receipt_pay_type').val(receipt_pay_type);
        window_frame.find('.cycle_pay_type').val(cycle_pay_type);
        window_frame.find('.total_fee').val(total_fee);

        $('#input_id').val(id);
        w_frame.show().find('.y-change-money-w').show().siblings().hide();
    });


    /*结算账务模块*/
    (function () {
        var js_from = $('#y-js-form');
        var obody = $('#y-js-tbody');
        var chech_box = $()
        /*正文 多选框点击事件，加上选中*/
        obody.on('click', '.y-checbox', function () {
            var self = $(this);
            var otr = self.closest('tr');
            var _id = otr.attr('data-id');
            var all_tr = obody.find('tr');
            cal_money(all_tr);
        });

        /*点击顶部多选框，全选*/
        $('#y-js-thead ').on('click', '.y-checbox', function () {
            var self = $(this);
            var checked = self.find('input[type=checkbox]').prop('checked');
            var all_tr = obody.find('tr');
            $('.y-all-account span').html('0.00');
            if (checked) {
                all_tr.find('input[type=checkbox]').prop('checked', true);
                cal_money(all_tr);
            } else {
                all_tr.find('input[type=checkbox]').prop('checked', false);
            }

        });

        //obj代表未循环的obj，勾选几个循环结果  more代表是否计算钱
        function cal_money(obj, more) {
            if (more == undefined) {
                more = true
            }

            var money_obj = $('.y-all-account span');
            var money = 0;
            var now_money;
            var id_list = [];
            $.each(obj, function (index, value) {
                var checked = $(value).find('input[type=checkbox]').prop('checked');
                if (checked) {
                    var _id = $(value).data('id');
                    id_list.push(_id);
                    if (more) {
                        now_money = $(value).find('.y-all-money span').html();
                        money += parseFloat(now_money);
                    }
                }

            });
            if (money == 0) {
                money = '0.00'
            }
            js_from.find('.y-input-frame').html('').append('<input type="hidden" value="' + id_list.join(',') + '" name="id_list">');
            money_obj.html(money);
        }
    })
    ();


    /*input框输入数字验证*/
    $('.y-num-check').keyup(function (ev) {
        var value = $(this).val();
        if (value) {
            last_input = value.slice(-1);
            var r = /[a-zA-Z]/;
            if (r.test(last_input)) {
                $(this).val(value.slice(0, -1));
            }
        }
    });

    /*防止弹窗过长*/
    var window_frame = $('.window-frame');
    var oh = window_frame.outerHeight();
    window_frame.find('form').css({
        'max-height': document.documentElement.clientHeight * 0.7 + 'px'
    })
})
;